package com.william.jdbcplus.core.dialects.ddl.uk;

import com.william.jdbcplus.core.dialects.ddl.uk.impl.MysqlUk;
import com.william.jdbcplus.core.dialects.ddl.uk.impl.OracleUk;
import com.william.jdbcplus.core.dialects.ddl.uk.impl.SqlServerUk;
import com.william.jdbcplus.common.enums.DbType;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class UkFactory {

    private static final Map<DbType, IUk> FACTORY_CACHE = new ConcurrentHashMap<>();

    static {
        for (DbType dbType : DbType.values()) {
            FACTORY_CACHE.put(dbType, getByDbType(dbType));
        }
    }

    /**
     * 获取实例
     *
     * @param dbType
     * @return
     */
    public static IUk getInstance(DbType dbType) {
        IUk iUk = FACTORY_CACHE.get(dbType);
        return iUk;
    }

    /**
     * 根据数据库类型选择不同建表方言
     *
     * @param dbType 数据库类型
     */
    private static IUk getByDbType(DbType dbType) {
        switch (dbType) {
            case MYSQL:
                return new MysqlUk();
            case ORACLE:
                return new OracleUk();
            case SQL_SERVER:
                return new SqlServerUk();
            case SQL_SERVER2005:
                return new SqlServerUk();
            default:
                return new OracleUk();
        }
    }
}
